package com.cloud.rou.im.router;

import com.cloud.rou.im.cluster.naming.node.ImServerInstance;
import com.cloud.rou.im.cluster.naming.node.InstancePostProcessorAdapt;
import com.cloud.rou.im.router.context.ImServerInstanceContext;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 * @since 2019-11-13 21:46
 */
public class CustomInstancePostProcessorAdapt extends InstancePostProcessorAdapt {
    @Override
    public void instanceAddedProcessor(ImServerInstance instance) {
        new Thread(() -> {
            //创建一个消息转发器
            WorkerReSender reSender = new WorkerReSender(instance);
            //建立转发的连接
            reSender.doConnect(instance);
        }).start();
    }

    @Override
    public void instanceRemovedProcessor(ImServerInstance instance) {
        ImServerInstanceContext instance1 = ImServerInstanceContext.getInstance();
        instance1.remove(instance);
        System.out.println(instance);
    }
}
